//对接口实现统一管理
import {requests,BMapRequests} from '@/api/index.js'


//封装api类
//异步函数

//用户请求对象
export class UserRequester {
    //用户密码登录请求
    //参数：用户信息对象
    reqLoginPsw = (userAccountMsg)=>requests({
        url:'user/mobile/login/password',
        method:'post',
        data:{
            phone:userAccountMsg.phone,
            password:userAccountMsg.password
        }
    })

    reqLoginPhone = (userAccountMsg)=>requests({
        url:'user/mobile/login/phone',
        method:'post',
        data:{
            phone:userAccountMsg.phone,
            numberCode:userAccountMsg.numberCode
        }
    })

    reqLoginCode = (phone)=>requests({
        url:'user/mobile/login/numberCode',
        method:'post',
        data:{
            phone:phone,
            codeLength:4
        }
    })

    reqUserReg = (userAccountMsg)=>requests({
        url:'user/mobile/login/register',
        method:'post',
        data:{
            nickname:userAccountMsg.nickname,
            phone:userAccountMsg.phone,
            password:userAccountMsg.password,
            numberCode:userAccountMsg.numberCode
        }
    })

    //查询粉丝数
    reqFansNum = ()=>requests({
        url:'user/mobile/private/queryFanNumber',
        method:'GET',
    })

    //查询小店
    reqPrivateShop = (userId)=>requests({
        url:'goods/mobile/goodsDetail/privateShop',
        method:'POST',
        data:{
            id:userId,
            page:0,
            size:2
        }
    })

    //查询拼租
    reqPrivateShare = (userId)=>requests({
        url:'goods/mobile/goodsDetail/privateShare',
        method:'POST',
        data:{
            id:userId,
            page: 0,
            size: Math.floor(Math.random()*20+1)
        }
    })


}


//商品请求类
export class GoodsRequester{
    //获取首页推荐商品
    reqGoodsList = (keyword,size)=>requests({
        url:'goods/mobile/goods/loadNew',
        //url:'m2/1714258-0-default/45601255'， //mock
        method:'POST',
        data:{
            "relativeTime": "1988-09-14 04:58:47",
            "size": size,
            "keyword": keyword
        }
    })


    ///获取商品的粗略信息（Card展示的信息）
    //请求参数：商品Id
    reqGoodsRough = (goodsId)=>requests({
        url:'goods/mobile/goodsDetail/queryGoodsRough',
        method:'GET',
        params:{
            id:goodsId
        }
    })

    //获取商品拼租信息
    reqGoodsShareInfo = (goodsId)=>requests({
        url:'goods/mobile/goodsDetail/share',
        method:'GET',
        params:{
            id:goodsId
        }
    })

    //获取商品详情数据
    //请求参数：商品Id
    reqGoodsDetial =  (goodsId)=>requests({
        url:"goods/mobile/goodsDetail/queryGoodsContent",
        method:'GET',
        params:{
            id:goodsId
        }
    })
    //获取商品想租浏览信息
    //请求参数：商品Id
    reqGoodsMsg = (goodsId)=>requests({
        url:"goods/mobile/goodsDetail/detail",
        method:'GET',
        params:{
            id:goodsId
        }
    })

    //获取卖家详细信息
    //请求query参数：卖家用户id
    reqMerchantDetial = (userId)=>requests({
        url:`goods/mobile/goodsDetail/merchant?id=${userId}`,
        method:'GET',
    })

    //设置喜欢收藏关注
    reqMerchantLike = (operateObject,operateType,id)=>requests({
        url:'goods/mobile/goodsUpdate/updateDetail',
        method:"POST",
        data:{
            operateObject:operateObject,
            operateType:operateType,
            id:id
        }
    })

    //获取搜索商品列表
    reqSearchGoodsList =(keyword,size)=>requests({
        url:'search/mobile/goods/search',
        method:"POST",
        data:{
            "searchWords": keyword,
            "pageNum": 0,
            "pageSize": size,
            "minBehotTime": "2044-08-14 06:47:42"
        }
    })


    //获取附近商品
    reqNearGoods = (latitude,longitude,size)=>requests({
        url:'search/mobile/map/distance',
        method:'POST',
        data:{
            "latitude": latitude,
            "longitude":longitude,
            "index": 0,
            "size": size
        }
    })

    //增加一条商品
    reqAddGoods = (goods)=>requests({
        url:"goods/mobile/goodsUpdate/addGoods",
        method:'POST',
        data:goods
    })
}


//百度地图请求对象
export class BMapRequester {
    constructor(ak){
        this.ak = ak;
    }


    //转化为百度地图坐标
    reqCoordsConvert = (longitude,latitude)=>BMapRequests({
        url:`geoconv/v1/?coords=${longitude},${latitude}&from=1&to=5&ak=${this.ak}`,
        method:'GET',
    })


    //获取当前IP位置
    //使用的是百度经纬度坐标
    reqIpAddress = ()=>BMapRequests({
        url:`location/ip?ak=${this.ak}&coor=bd09ll`,
        method:'GEt'
    })



}